namespace TS2015.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class database1812 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.TbChucNang_Quyen", "MaQuyen", "dbo.TbLoaiND");
            DropForeignKey("dbo.TbNguoiDung", "MaLoaiND", "dbo.TbLoaiND");
            //DropForeignKey("dbo.TbTruong", "MaKhuVuc", "dbo.TbKhuVuc");
            DropForeignKey("dbo.TbThiSinh", "TbTruong_MaTruong", "dbo.TbTruong");
            //DropForeignKey("dbo.TbTruong", "MaTinh", "dbo.TbTinh");
            DropIndex("dbo.TbNguoiDung", new[] { "MaLoaiND" });
            DropIndex("dbo.TbThiSinh", new[] { "TbTruong_MaTruong" });
            //DropIndex("dbo.TbTruong", new[] { "MaTinh" });
            //DropIndex("dbo.TbTruong", new[] { "MaKhuVuc" });
            CreateTable(
                "dbo.TbQuyen",
                c => new
                    {
                        MaQuyen = c.Int(nullable: false, identity: true),
                        Quyen = c.String(nullable: false, maxLength: 50),
                        TrangThai = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MaQuyen);
            
            CreateTable(
                "dbo.TbKhoiThi_MonTotNghiep",
                c => new
                    {
                        MaMon = c.Int(nullable: false),
                        MaKhoiThi = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MoTa = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => new { t.MaMon, t.MaKhoiThi })
                .ForeignKey("dbo.TbMonTotNghiep", t => t.MaMon)
                .ForeignKey("dbo.TbKhoiThi", t => t.MaKhoiThi)
                .Index(t => t.MaMon)
                .Index(t => t.MaKhoiThi);
            
            CreateTable(
                "dbo.TbThiSinh_HeDaoTao",
                c => new
                    {
                        IDTS_HDT = c.Int(nullable: false, identity: true),
                        MaTS = c.String(maxLength: 10, fixedLength: true),
                        MaHeDaoTao = c.Int(nullable: false),
                        MoTa = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => t.IDTS_HDT)
                .ForeignKey("dbo.TbHeDaoTao", t => t.MaHeDaoTao, cascadeDelete: true)
                .ForeignKey("dbo.TbThiSinh", t => t.MaTS)
                .Index(t => t.MaTS)
                .Index(t => t.MaHeDaoTao);
            
            CreateTable(
                "dbo.TbTruongTHPT",
                c => new
                    {
                        IDTruong = c.Int(nullable: false, identity: true),
                        MaTruong = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        TenTruong = c.String(nullable: false, maxLength: 200),
                        DiaChi = c.String(nullable: false, maxLength: 500),
                        MaTinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaKhuVuc = c.String(nullable: false, maxLength: 10, fixedLength: true),
                    })
                .PrimaryKey(t => t.IDTruong)
                .ForeignKey("dbo.TbKhuVuc", t => t.MaKhuVuc)
                .ForeignKey("dbo.TbTinh", t => t.MaTinh)
                .Index(t => t.MaTinh)
                .Index(t => t.MaKhuVuc);
            
            CreateTable(
                "dbo.TbTruongDH",
                c => new
                    {
                        MaTruongDH = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        TenTruongDH = c.String(nullable: false, maxLength: 200),
                        DiaChi = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => t.MaTruongDH);
            
            CreateTable(
                "dbo.TbThongKe",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        LuongTruyCap = c.Long(nullable: false,defaultValue:0),
                    })
                .PrimaryKey(t => t.ID);
            
            AddColumn("dbo.TbChucNang", "CssIcon", c => c.String(maxLength: 50));
            AddColumn("dbo.TbNguoiDung", "MaQuyen", c => c.Int(nullable: false));
            AddColumn("dbo.TbThiSinh", "SBD", c => c.String(maxLength: 15, fixedLength: true));
            AddColumn("dbo.TbThiSinh", "MaTruongDH", c => c.String(nullable: false, maxLength: 10, fixedLength: true));
            AddColumn("dbo.TbThiSinh", "TinhTrangTotNghiep", c => c.Int());
            AddColumn("dbo.TbThiSinh", "NoiDaoTao", c => c.Int(nullable: false));
            AddColumn("dbo.TbDoiTuongUuTien", "NhomDoiTuong", c => c.Int(nullable: false));
            AlterColumn("dbo.TbChucNang_Quyen", "TrangThai", c => c.Int(nullable: false));
            AlterColumn("dbo.TbChucNang", "TenCN", c => c.String(nullable: false, maxLength: 50));
            AlterColumn("dbo.TbChucNang", "Link", c => c.String(nullable: false, maxLength: 500, unicode: false));
            AlterColumn("dbo.TbChucNang", "MaCNCha", c => c.Int(nullable: false));
            AlterColumn("dbo.TbChucNang", "TrangThai", c => c.Int(nullable: false));
            AlterColumn("dbo.TbThiSinh", "SoDienThoai", c => c.String(nullable: false, maxLength: 11, fixedLength: true));
            AlterColumn("dbo.TbThiSinh", "TrangThaiDangKi", c => c.Int(nullable: false));
            AlterColumn("dbo.TbThiSinh", "LanSuaCuoi", c => c.DateTime(nullable: false));
            AlterColumn("dbo.TbDiemTotNghiep", "Diem", c => c.Double());
            CreateIndex("dbo.TbNguoiDung", "MaQuyen");
            CreateIndex("dbo.TbThiSinh", "IDTruong");
            CreateIndex("dbo.TbThiSinh", "MaTruongDH");
            AddForeignKey("dbo.TbChucNang_Quyen", "MaQuyen", "dbo.TbQuyen", "MaQuyen");
            AddForeignKey("dbo.TbNguoiDung", "MaQuyen", "dbo.TbQuyen", "MaQuyen");
            AddForeignKey("dbo.TbThiSinh", "IDTruong", "dbo.TbTruongTHPT", "IDTruong");
            AddForeignKey("dbo.TbThiSinh", "MaTruongDH", "dbo.TbTruongDH", "MaTruongDH");
            DropColumn("dbo.TbChucNang", "MoTa");
            DropColumn("dbo.TbChucNang", "Anh");
            DropColumn("dbo.TbNguoiDung", "MaLoaiND");
            DropColumn("dbo.TbThiSinh", "TbTruong_MaTruong");
            DropTable("dbo.TbLoaiND");
            //DropTable("dbo.TbTruong");
        }
        
        public override void Down()
        {
            //CreateTable(
                //"dbo.TbTruong",
                //c => new
                //    {
                //        MaTruong = c.String(nullable: false, maxLength: 10, fixedLength: true),
                //        TenTruong = c.String(nullable: false, maxLength: 200),
                //        DiaChi = c.String(nullable: false, maxLength: 500),
                //        MaTinh = c.String(nullable: false, maxLength: 10, fixedLength: true),
                //        MaKhuVuc = c.String(nullable: false, maxLength: 10, fixedLength: true),
                //    })
                //.PrimaryKey(t => t.MaTruong);
            
            CreateTable(
                "dbo.TbLoaiND",
                c => new
                    {
                        MaLoaiND = c.Int(nullable: false, identity: true),
                        Quyen = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(),
                    })
                .PrimaryKey(t => t.MaLoaiND);
            
            AddColumn("dbo.TbThiSinh", "TbTruong_MaTruong", c => c.String(nullable: false, maxLength: 10, fixedLength: true));
            AddColumn("dbo.TbNguoiDung", "MaLoaiND", c => c.Int(nullable: false));
            AddColumn("dbo.TbChucNang", "Anh", c => c.String(maxLength: 100, unicode: false));
            AddColumn("dbo.TbChucNang", "MoTa", c => c.String(maxLength: 500));
            DropForeignKey("dbo.TbKhoiThi_MonTotNghiep", "MaKhoiThi", "dbo.TbKhoiThi");
            DropForeignKey("dbo.TbKhoiThi_MonTotNghiep", "MaMon", "dbo.TbMonTotNghiep");
            DropForeignKey("dbo.TbThiSinh", "MaTruongDH", "dbo.TbTruongDH");
            DropForeignKey("dbo.TbTruongTHPT", "MaTinh", "dbo.TbTinh");
            DropForeignKey("dbo.TbThiSinh", "IDTruong", "dbo.TbTruongTHPT");
            DropForeignKey("dbo.TbTruongTHPT", "MaKhuVuc", "dbo.TbKhuVuc");
            DropForeignKey("dbo.TbThiSinh_HeDaoTao", "MaTS", "dbo.TbThiSinh");
            DropForeignKey("dbo.TbThiSinh_HeDaoTao", "MaHeDaoTao", "dbo.TbHeDaoTao");
            DropForeignKey("dbo.TbNguoiDung", "MaQuyen", "dbo.TbQuyen");
            DropForeignKey("dbo.TbChucNang_Quyen", "MaQuyen", "dbo.TbQuyen");
            DropIndex("dbo.TbTruongTHPT", new[] { "MaKhuVuc" });
            DropIndex("dbo.TbTruongTHPT", new[] { "MaTinh" });
            DropIndex("dbo.TbThiSinh_HeDaoTao", new[] { "MaHeDaoTao" });
            DropIndex("dbo.TbThiSinh_HeDaoTao", new[] { "MaTS" });
            DropIndex("dbo.TbThiSinh", new[] { "MaTruongDH" });
            DropIndex("dbo.TbThiSinh", new[] { "IDTruong" });
            DropIndex("dbo.TbKhoiThi_MonTotNghiep", new[] { "MaKhoiThi" });
            DropIndex("dbo.TbKhoiThi_MonTotNghiep", new[] { "MaMon" });
            DropIndex("dbo.TbNguoiDung", new[] { "MaQuyen" });
            AlterColumn("dbo.TbDiemTotNghiep", "Diem", c => c.Double(nullable: false));
            AlterColumn("dbo.TbThiSinh", "LanSuaCuoi", c => c.DateTime());
            AlterColumn("dbo.TbThiSinh", "TrangThaiDangKi", c => c.Boolean());
            AlterColumn("dbo.TbThiSinh", "SoDienThoai", c => c.String(maxLength: 11, fixedLength: true));
            AlterColumn("dbo.TbChucNang", "TrangThai", c => c.Int());
            AlterColumn("dbo.TbChucNang", "MaCNCha", c => c.Int());
            AlterColumn("dbo.TbChucNang", "Link", c => c.String(maxLength: 500, unicode: false));
            AlterColumn("dbo.TbChucNang", "TenCN", c => c.String(maxLength: 50));
            AlterColumn("dbo.TbChucNang_Quyen", "TrangThai", c => c.Boolean());
            DropColumn("dbo.TbDoiTuongUuTien", "NhomDoiTuong");
            DropColumn("dbo.TbThiSinh", "NoiDaoTao");
            DropColumn("dbo.TbThiSinh", "TinhTrangTotNghiep");
            DropColumn("dbo.TbThiSinh", "MaTruongDH");
            DropColumn("dbo.TbThiSinh", "SBD");
            DropColumn("dbo.TbNguoiDung", "MaQuyen");
            DropColumn("dbo.TbChucNang", "CssIcon");
            DropTable("dbo.TbThongKe");
            DropTable("dbo.TbTruongDH");
            DropTable("dbo.TbTruongTHPT");
            DropTable("dbo.TbThiSinh_HeDaoTao");
            DropTable("dbo.TbKhoiThi_MonTotNghiep");
            DropTable("dbo.TbQuyen");
            //CreateIndex("dbo.TbTruong", "MaKhuVuc");
            //CreateIndex("dbo.TbTruong", "MaTinh");
            CreateIndex("dbo.TbThiSinh", "TbTruong_MaTruong");
            CreateIndex("dbo.TbNguoiDung", "MaLoaiND");
            //AddForeignKey("dbo.TbTruong", "MaTinh", "dbo.TbTinh", "MaTinh");
            AddForeignKey("dbo.TbThiSinh", "TbTruong_MaTruong", "dbo.TbTruong", "MaTruong");
            AddForeignKey("dbo.TbTruong", "MaKhuVuc", "dbo.TbKhuVuc", "MaKhuVuc");
            AddForeignKey("dbo.TbNguoiDung", "MaLoaiND", "dbo.TbLoaiND", "MaLoaiND");
            AddForeignKey("dbo.TbChucNang_Quyen", "MaQuyen", "dbo.TbLoaiND", "MaLoaiND");
        }
    }
}
